﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;

namespace AricentTestProject
{
    public class BasePage : System.Web.UI.Page
    {

        public string UserIP
        {
            get
            {
                string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (ip == null || ip.ToLower() == "unknown")
                    ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                return ip;
            }
        }

        public UserInfo CurrentUser
        {
            get
            {
                return (UserInfo)Session["User"];
            }

            protected set
            {
                value.IP = UserIP;
                value.SessionId = Session.SessionID;
                value.LastActivity = DateTime.Now;
                Session["User"] = value;
                value.save();
            }
        }
    }
}
